<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Traning extends Model
{
    use HasFactory;

    protected $table = "training";
    protected $appends = ['is_join'];

    public function traningCourseRelation()
    {
        return $this->hasMany(TraningCourseRelation::class);
    }
    public function course()
    {
        return $this->hasManyThrough(Course::class, TraningCourseRelation::class, 'traning_id', 'id','id', 'course_id');
    }
    
    public function joinUser()
    {
        return $this->hasMany(UserTraningRelation::class);
    }
   
    public  function getIsJoinAttribute()
    {
        return (int)$this->joinUser()->where('user_id', 1)->exists();
    }
}
